import { Modal } from "antd";
import type { Material } from "@/pages/base/material/entity";
import DynamicQueryTable, { SelectionType } from "@/components/report/DynamicQueryTable";
import { useState } from "react";

interface MultiMaterialSelectorProps {
	open: boolean;
	onCancel: () => void;
	onOk: (selectedMaterials: Material[]) => void;
}

const MultiMaterialSelector:React.FC<MultiMaterialSelectorProps> = ({ open, onCancel, onOk }) => {
  
  // 选中的物料
  const [selectedMaterials, setSelectedMaterials] = useState<Material[]>([]);

  const handleOk = () => {
		onOk(selectedMaterials);
	};

	return (
		<Modal title="选择物料" open={open} onCancel={onCancel} onOk={handleOk} width={800} destroyOnClose>
			<DynamicQueryTable 
        reportCode="material_seach_report" 
        selectionType={SelectionType.CHECKBOX}
        onSelectChange={(selectedRows) => {setSelectedMaterials(selectedRows)}}  
      />
		</Modal>
	);
}

export default MultiMaterialSelector;